package com.adingxiong.quickstart.project.controller.util;

import com.adingxiong.quickstart.util.GetRealIp;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName IPController
 * @Description TODO
 * @Author xiongchao
 * @Date 2020/5/29 9:19
 **/

@RestController
@Api(tags = "IP地址相关")
@RequestMapping("/ip")
public class IPController {

    @RequestMapping(value = "/getIp" ,method = RequestMethod.GET)
    public Map<String,String> getRealIp(HttpServletRequest request){
        Map<String,String> res = new HashMap<>();
        String ip = GetRealIp.getIpaddr(request);
        String address = GetRealIp.getAddress(ip);
        res.put("ip",ip);
        res.put("address",address);
        return res;
    }
}
